home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bchelp10.zip / TI644.ASC < prev    next >
Text File  |  1991-09-17  |  2KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  644
  9.   VERSION  :  All
  10.        OS  :  PC DOS
  11.      DATE  :  September 17, 1991                       PAGE  :  1/1
  12.  
  13.     TITLE  :  Windows DLL and Fatal Exit Code=0x001A
  14.  
  15.  
  16.  
  17.  
  18.   Fatal Exit Code=0x001A is  not  documented by the SDK but what it
  19.   seems to mean is that an attempt has been made to FreeLibrary() a
  20.   DLL which has registered a  GLOBALCLASS window class still in use
  21.   by another open window.
  22.  
  23.   For  example, a window class with  the  style  CS_GLOBALCLASS  is
  24.   registered  in order to make a  custom  control  (like  "button",
  25.   "checkbox",  etc.).    In the main program, a LoadLibrary() and a
  26.   CreateWindow()  are executed to create a  child  window  of  that
  27.   custom class.
  28.  
  29.   In a WM_DESTROY message handler, a FreeLibrary() is done followed
  30.   by a PostQuitMessage(0).    Seems like a reasonable procedure but
  31.   results in a Fatal Exit Code=0x001A from Windows when the  DLL is
  32.   used. Puzzled?
  33.  
  34.   A careful  reading of the SDK reference indicates that WM_DESTROY
  35.   is sent to a parent window BEFORE its children are destroyed.
  36.  
  37.   The library freed from memory by the FreeLibrary() call contained
  38.   the necessary class information for the child window.  Since this
  39.   is  all  happening  inside of a WM_DESTROY  handler,  this  child
  40.   window  isn't  closed  yet  and  the  result  is the  Fatal  Exit
  41.   Code=0x001A.
  42.  
  43.   One solution is to trap WM_CLOSE and close  the  affected windows
  44.   prior to the FreeLibrary() call:
  45.  
  46.     case WM_CLOSE:
  47.       DestroyWindow(handle of main window);
  48.       DestroyWindow(handle of first child window);
  49.       DestroyWindow(handle of second child window);
  50.              :
  51.              :
  52.       FreeLibrary(library handle);
  53.       break;
  54.  
  55.   This  effectively forces Windows to close  all  of  the  children
  56.   BEFORE  freeing the library that they are based on.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.